#include "Hash.h"

#include <string>
#include <utility>

namespace MOE
{
	namespace Core
	{

		// Function to convert string to hash. Used by all MOE codes.
		tHashValue StringToHash(const char8* str)
		{
			// Use FNV-1a hash over str.
			static const tHashValue kFNVOffsetBasis = 2166136261U;
			static const tHashValue kFNVPrime = 16777619U;
			tHashValue seed = kFNVOffsetBasis;
			if (str != nullptr)
			{
				while (*str != '\0')
				{
					seed ^= static_cast<tHashValue>(*str);
					seed *= kFNVPrime;
					++str;
				}
			}

			return seed;
		}

	}
}
